import { _decorator, Button, Component, Label, Node, Slider, Sprite, Toggle, Vec2, Vec3 } from 'cc';
import { UIManager } from '../UIManager';
import { LanauageManager } from '../LanauageManager';
import { GameData, taskCfg } from '../GameData';
import { HttpClient } from '../net/HttpClient';
import { EventManager } from '../EventManager';
import { AudioMgr } from '../AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('taskItem')
export class taskItem extends Component {

    @property(Label)
    desLab:Label = null;

    @property(Label)
    rewardLab:Label = null;

    @property(Button)
    getBtn:Button = null;

    @property(Label)
    getBtnLab:Label = null;

    taskCfg:taskCfg;

    onEnable() {

    }

    refresh(itemData:any){
        this.taskCfg = itemData;

        this.desLab.string = this.taskCfg.taskType.replace("&1", this.taskCfg.process + "").replace("&2", this.taskCfg.process + "");

        this.rewardLab.string = this.taskCfg.taskReward + "";

        if (this.taskCfg.status == 2){
            this.getBtn.interactable = false;
            this.getBtnLab.string = "已领取";
        }
        else if (this.taskCfg.status == 1){
            this.getBtn.interactable = true;
            this.getBtnLab.string = "领取";
        }
        else if (this.taskCfg.status == 0)
        {
            this.getBtn.interactable = true;
            this.getBtnLab.string = "去完成";
        }
    }

    onClickHandler(event:Event, str:string){
        if (this.taskCfg.status == 2){

        }
        else if (this.taskCfg.status == 1){
            HttpClient.getInstance().sendGetTaskReward(this.taskCfg.id);
        }
        else if (this.taskCfg.status == 0)
        {
            if (this.taskCfg.type2 == 2 || this.taskCfg.type2 == 3 || this.taskCfg.type2 == 5|| this.taskCfg.type2 == 6|| this.taskCfg.type2 == 9|| this.taskCfg.type2 == 12){
                EventManager.eventTarget.emit(EventManager.GAME_CHANGE_VIEW, 4);
            }
            else if (this.taskCfg.type2 == 13){
                EventManager.eventTarget.emit(EventManager.GAME_CHANGE_VIEW, 1);
            }
            else{
                EventManager.eventTarget.emit(EventManager.GAME_CHANGE_VIEW, 2);
            }
        }
    }
}

